package cn.gene.timeyan.ums.webapi.ums.service.impl;

import cn.gene.timeyan.pojo.ums.model.SearchRecord;
import cn.gene.timeyan.search.service.ICooperationforService;
import cn.gene.timeyan.search.service.ILostService;
import cn.gene.timeyan.search.service.ISearchService;
import cn.gene.timeyan.search.service.IShareForService;
import cn.gene.timeyan.ums.service.ISearchRecordService;
import cn.gene.timeyan.ums.webapi.ums.mapper.SearchRecordMapper;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 搜索记录信息 服务实现类
 * </p>
 *
 * @author LWG
 * @since 2022-08-06
 */
@Service
public class SearchRecordServiceImpl implements ISearchRecordService {
    @DubboReference
    private ICooperationforService cooperationforService;
    @DubboReference
    private ILostService iLostService;
    @DubboReference
    private ISearchService iSearchService;
    @DubboReference
    private IShareForService iShareForService;
    @Autowired
    private SearchRecordMapper searchRecordMapper;



    @Override
    public void loadLostKeyWord(Long userId, String keyWord) {
        String key = iLostService.getKeyWord(keyWord);
        SearchRecord searchRecord = new SearchRecord();
        searchRecord.setUserId(userId);
        searchRecord.setSearchAreaUserId(0l);
        searchRecord.setSearchContent(key);
        searchRecordMapper.insertKeyWord(searchRecord);

    }
    @Override
    public void loadAllKeyWord(Long userId, String keyWord) {
        String key = iSearchService.getKeyWord(keyWord);
        SearchRecord searchRecord = new SearchRecord();
        searchRecord.setUserId(userId);
        searchRecord.setSearchAreaUserId(1l);
        searchRecord.setSearchContent(key);
        searchRecordMapper.insertKeyWord(searchRecord);
    }
    @Override
    public void loadShareKeyWord(Long userId, String keyWord) {
        String key = iShareForService.getKeyWord(keyWord);
        SearchRecord searchRecord = new SearchRecord();
        searchRecord.setUserId(userId);
        searchRecord.setSearchAreaUserId(2l);
        searchRecord.setSearchContent(key);
        searchRecordMapper.insertKeyWord(searchRecord);
    }
    @Override
    public void loadCooperationKeyWord(Long userId, String keyWord) {
        String key = cooperationforService.getKeyWord(keyWord);
        SearchRecord searchRecord = new SearchRecord();
        searchRecord.setUserId(userId);
        searchRecord.setSearchAreaUserId(3l);
        searchRecord.setSearchContent(key);
        searchRecordMapper.insertKeyWord(searchRecord);
    }

    @Override
    public List getRecord(Long userId) {
     List list=searchRecordMapper.selectRecord(userId);
     return list;
    }
}

